package jp.ddo.trismegistos.framework.util;

import jp.ddo.trismegistos.framework.WrapRuntimeException;

public final class ClassUtil {

	private ClassUtil() {
	}

	public static Object newInstance(final String className) {
		try {
			return Class.forName(className);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
			return null;
		}
	}

	@SuppressWarnings("unchecked")
	public static <T> T newInstance(final Class<?> clazz) {

		try {
			return (T) clazz.newInstance();
		} catch (final Throwable t) {
			throw new WrapRuntimeException(
					"An error creating a new instance. ClassName is "
							+ clazz.getName() + ". Cause is " + t.getCause()
							+ ".", t);
		}
	}
}
